package com.rmdjzz.slmmn.config;

import com.rmdjzz.slmmn.interceptor.AdminInterceptor;
import com.rmdjzz.slmmn.interceptor.UserInterceptor;
import org.springframework.boot.web.servlet.filter.OrderedHiddenHttpMethodFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @作者 张绍鑫
 * @创建时间 2023/5/30
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {
    //设置文件虚拟路径映射
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //localhost/song
        //C:\song\
        registry.addResourceHandler("/song/**").addResourceLocations("file:C:\\slmmn\\song\\");
        //localhost/song
        //C:\song\
        registry.addResourceHandler("/singer/**").addResourceLocations("file:C:\\slmmn\\singer\\");
    }





    @Resource
    private AdminInterceptor loginInterceptor;
    @Resource
    private UserInterceptor userInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册自己的拦截器,并设置拦截的请求路径
        //addPathPatterns为拦截此请求路径的请求
        //excludePathPatterns为不拦截此路径的请求
        registry.addInterceptor(loginInterceptor).addPathPatterns(
                "/admin/resetSoaring",//拦截飙升榜重置功能
                "/admin/commentPage",//拦截评论查看功能
                "/admin/commentDel",//拦截根据id删除评论
                "/admin/commentDelIds",//拦截批量删除评论
                "/admin/hot",//拦截热歌榜单
                "/admin/soaring",//拦截飙升榜单
                "/singer/addSinger",//拦截添加歌手
                "/singer/deleteSinger",//拦截删除歌手
                "/singer/searchSinger",//拦截查询歌手
                "/admin/songIns",//拦截添加歌曲
                "/admin/songPage",//拦截歌曲分页
                "/admin/songDel",//拦截删除歌曲
                "/admin/songDelIds",//拦截批量删除歌曲
                "/admin/songQueryById",//拦截根据id查询歌曲
                "/admin/songUpdateWords",//拦截更新歌词
                "/admin/userIns",//拦截添加用户
                "/admin/userPage",//拦截查看用户
                "/admin/userDel",//拦截删除用户
                "/admin/userDelIds",//拦截删除用户
                "/admin/userQueryById",//拦截根据id查看用户
                "/admin/userUpdate",//拦截更新用户、
                "/admin/dataAnalysis"//拦截首页数据分析

        );
        registry.addInterceptor(userInterceptor).addPathPatterns(
                "/user/userComment","拦截用户评论",
                "/user/love",//拦截用户收藏
                "/user/loveList",//拦截用户收藏歌单
                "/user/playLoveList/*",//拦截播放收藏歌单
                "/user/userSafety",//拦截密码修改
                "/user/userChangeMessage",//拦截用户信息修改
                "/user/userMessages"//拦截个人信息页

        );
    }

    @Bean
    public OrderedHiddenHttpMethodFilter hiddenHttpMethodFilter(){
        return new OrderedHiddenHttpMethodFilter();
    }

}
